package com.websuites.esb.repository;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Iterator;

import com.websuites.core.repository.Dict;
import com.websuites.core.repository.Field;

@SuppressWarnings("unchecked")
public class Bex
{
	private HashMap mapProps    	= new HashMap();
	private List listParams     	= new ArrayList();
	private List listParamsSession	= new ArrayList();
	private List listFields     	= new ArrayList();
	private List listSpells     	= new ArrayList();
	private List listColumns     	= new ArrayList();
	private HashMap mapForwards 	= new HashMap();
	private Dict dict				= null;
	
	public String getBex()
	{
		return (String)mapProps.get("id");
	}
	
	public String getType()
	{
		return (String)mapProps.get("type");
	}
		
	public void setParams(List listParams)
	{
		this.listParams = listParams;
	}
	
	public void setParamsSession(List listParamsSession)
	{
		this.listParamsSession = listParamsSession;
	}

	public void setFields(List listFields)
	{
		this.listFields = listFields;
	}

	public void setSpells(List listSpells)
	{
		this.listSpells = listSpells;
	}

	public void setForwards(HashMap mapForwards)
	{
		this.mapForwards = mapForwards;
	}

	public void setColumns(List listColumns)
	{
		this.listColumns = listColumns;
	}

	public void setDict(Dict dict)
	{
		this.dict = dict;
	}

	public int getParamCount()
	{
		return listParams.size();
	}
	
	public int getFieldCount()
	{
		return listFields.size();
	}

	public int getSpellCount()
	{
		return listSpells.size();
	}

	public int getColumnCount()
	{
		return listColumns.size();
	}

	public Iterator getParamIterator()
	{
		return listParams.iterator();
	}
	
	public Iterator getParamsSessionIterator()
	{
		return listParamsSession.iterator();
	}

	public Iterator getFieldIterator()
	{
		return listFields.iterator();
	}
	
	public Iterator getSpellIterator()
	{
		return listSpells.iterator();
	}

	public List getFieldList()
	{
		return listFields;
	}

	public List getSpellList()
	{
		return listSpells;
	}

	public Iterator getColumnIterator()
	{
		return listColumns.iterator();
	}
	
	public List getColumnList()
	{
		return listColumns;
	}

	public Forward getForward(String sForwardCode)
	{
		if (mapForwards.containsKey(sForwardCode))
		{
			return (Forward)mapForwards.get(sForwardCode);
		}
		return null;
	}
	
	public Dict getDict()
	{
		return dict;
	}
	
	public String getParamType(String sParamName)
	{
		Iterator it = listParams.iterator();
		while (it.hasNext())
		{
			Param param = (Param)it.next();
			String sName = param.getName();
			if (sName.equals(sParamName))
			{
				return param.getType();
			}
		}
		return null;
	}

	public String getParamValue(String sParamName)
	{
		Iterator it = listParams.iterator();
		while (it.hasNext())
		{
			Param param = (Param)it.next();
			String sName = param.getName();
			if (sName.equals(sParamName))
			{
				return param.getValue();
			}
		}
		return "";
	}

	public String getParamTrans(String sParamName)
	{
		Iterator it = listParams.iterator();
		while (it.hasNext())
		{
			Param param = (Param)it.next();
			String sName = param.getName();
			if (sName.equals(sParamName))
			{
				return param.getTrans();
			}
		}
		return "";
	}

	public String getParamSessionValue(String sParamName)
	{
		Iterator it = listParamsSession.iterator();
		while (it.hasNext())
		{
			ParamSession param = (ParamSession)it.next();
			String sName = param.getName();
			if (sName.equals(sParamName))
			{
				return param.getValue();
			}
		}
		return "";
	}

	public String getFiledTarget(String sFieldName)
	{
		Iterator it = listFields.iterator();
		while (it.hasNext())
		{
			Field field = (Field)it.next();
			String sName = field.getName();
			if (sName.equals(sFieldName))
			{
				return field.getTarget();
			}
		}
		return null;
	}

	public String getFiledDict(String sFieldName)
	{
		Iterator it = listFields.iterator();
		while (it.hasNext())
		{
			Field field = (Field)it.next();
			String sName = field.getName();
			if (sName.equals(sFieldName))
			{
				return field.getTarget();
			}
		}
		return null;
	}

	public String getPropValue(String sPropKey)
	{
		if (mapProps.containsKey(sPropKey))
		{
			return (String)mapProps.get(sPropKey);
		}
		else
		{
			return null;
		}
	}

	public Iterator getPropIterator()
	{
		return mapProps.entrySet().iterator();
	}

	public void setProps(HashMap mapProp)
	{
		this.mapProps = mapProp;
	}	
}
